import Toast from '@vant/weapp/toast/toast';
Page({
  /**
   * 页面的初始数据
   */
  data: {
    rankisShow: '', //银行排名显示隐藏
    effectisShow: '', //走访成效显示隐藏
    performance: '',//绩效排名
    jspmIsshow: '',//竞赛排名
    uncommittedPopIshow: false,
  },
  goback() {
    console.log('11')
    wx.navigateBack({
      delta: 1
    })
  },
  //去搜索
  tosearch() {
    wx.navigateTo({
      url: "/packageA/pages/homelink/zhaoqiye/zhaoqiye",
    });
  },

  goSearch(e) {
    const type = e.currentTarget.dataset.id
    // console.log(type, '111')
    if (type == 1) {
      const userInfo = wx.getStorageSync('userInfo');
      wx.navigateTo({
        url: "/pages/visitList/visitList",
      });
      // if (userInfo.agencyCode) {
      //   wx.navigateTo({
      //     url: "/pages/visitList/visitList",
      //   });
      // } else {
      //   wx.navigateTo({
      //     url: "../../packageA/pages/notBind/notBind",
      //   });
      // }
    } else if (type == 2) {
      const corpRole = wx.getStorageSync('userInfo').corpRole
      console.log(corpRole, 'corpRolecorpRole')
      wx.setStorageSync('corpType', e.currentTarget.dataset.id)
      if (corpRole.indexOf('cbrc') != -1) {
        // 跳转银监页面
        wx.navigateTo({
          url: `../../packageA/pages/zoufangTj/zoufangTj`,
        });
      } else if (corpRole.indexOf('manager') != -1) {
        // 跳转银行经理页面
        wx.navigateTo({
          url: `../../packageA/pages/zoufangJL/zoufangJL`,
        });
      } else if (corpRole.indexOf('fir_admin') != -1) {
        console.log('一级银行')
        // 一级银行跳转 有总览的页面并且传参'1'
        const agencyCode = wx.getStorageSync('userInfo').agencyCode
        wx.navigateTo({
          url: `../../packageA/pages/zoufangYBJ/zoufangYBJ?bankId=${agencyCode}&bankLevel=1`,
        });
      } else {
        // 二级银行跳转 有总览的页面并且传参'2'
        const agencyCode = wx.getStorageSync('userInfo').agencyCode
        wx.navigateTo({
          url: `../../packageA/pages/zoufangYBJ/zoufangYBJ?bankId=${agencyCode}&bankLevel=2`,
        });
      }
      // wx.navigateTo({
      //   url: "../../packageB/pages/statisticalAnalysis/statisticalAnalysis",
      // });
    } else if (type == 3) {
      wx.navigateTo({
        url: '../../packageB/pages/visitEffect/visitEffect',
      });
    } else if (type == 4) {
      const corpRole = wx.getStorageSync('userInfo').corpRole || []
      if (corpRole.includes('cbrc')) {
        wx.navigateTo({
          url: '../../packageB/pages/ranking/ranking',
        });
      } else {
        wx.navigateTo({
          url: '../../packageB/pages/secondRanking/secondRanking',
        });
      }
    } else if (type == 5) {
      wx.navigateTo({
        url: '../../packageB/pages/performanceRank/performanceRank',
      });
    } else if (type == 7) {
      wx.navigateTo({
        url: '../../sub_qiangdan/reservation/reservation',
      });
    } else if (type == 8) {
      // 竞赛成绩
      let corpRole = wx.getStorageSync('userInfo').corpRole
      console.log(corpRole.includes('manager'), '22')
      if (corpRole.includes('cbrc')) {
        wx.navigateTo({
          url: '../../sub_qiangdan/ranking/ranking',
        });
      } else if (corpRole.includes('fir_admin')) {
        let userInfo = wx.getStorageSync('userInfo')
        let bankId = userInfo.highLevelBankId
        wx.navigateTo({
          url: `../../sub_qiangdan/internalRanking/internalRanking?bankId=${bankId}&myLeve=null`
          // url: '../../sub_qiangdan/internalRanking/internalRanking'
        });
        // wx.navigateTo({
        //   // url: '../../sub_qiangdan/ranking/ranking',

        //   url: '../../sub_qiangdan/internalRanking/internalRanking',
        // });
      }

    } else if (type == 9) {
      let userId = wx.getStorageSync('userInfo').userId
      console.log(userId, 'userId')
      getApp().globalData.request(
        '/corpVisit/queryLaborRaceRankByUser', { userId: userId },
        "POST"
      ).then(res => {
        if (res.data != null) {
          wx.navigateTo({
            url: `/sub_qiangdan/performanceRank/performanceRank?userId=${userId}`
          })
        } else {
          console.log(res, 'rewws');
          this.setData({
            uncommittedPopIshow: true
          })
          setTimeout(() => {
            this.setData({
              uncommittedPopIshow: false
            })
          }, 2000);
        }

      })


    } else {
      wx.navigateTo({
        url: '../../packageB/pages/reservation/reservation',
      });
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const corpRole = wx.getStorageSync('userInfo').corpRole || []
    console.log(corpRole, 'corpRole')
    let rankisShow = ''
    let jspmIsshow = ''
    let effectisShow = ''
    let performance = ''
    // 走访成效 银监显示
    if (corpRole.includes('cbrc')) {
      effectisShow = true
    } else {
      effectisShow = false
    }
    // 银行排名 银监 一级行显示
    if (corpRole.includes('cbrc') || corpRole.includes('fir_admin')) {
      rankisShow = true
    } else {
      rankisShow = false
    }
    // 竞赛排名 银监 一级行显示
    if (corpRole.includes('cbrc') || corpRole.includes('fir_admin')) {
      jspmIsshow = true
    } else {
      jspmIsshow = false
    }
    // 绩效排名隐藏
    if (!corpRole.includes('cbrc')) {
      performance = true
    }
    this.setData({
      rankisShow: rankisShow,
      effectisShow: effectisShow,
      performance: performance,
      jspmIsshow: jspmIsshow
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() { },
});